package com.example.demo.practice.ui;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.demo.practice.R;

/**
 * Created by hanbo on 2018-01-06.
 */

public class TitleView extends LinearLayout {

    private GradientTextView textView;

    public TitleView(Context context) {
        super(context);
    }

    public TitleView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setGravity(Gravity.CENTER);
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TitleView);
        String title = typedArray.getString(R.styleable.TitleView_title);
        textView = new GradientTextView(context);
        textView.setText(title);
        textView.setTextSize(20);
        typedArray.recycle();
        addView(textView);
    }

    /**
     * 动态设置标题
     * @param title{String} 标题
     */
    public void setText(String title) {
        textView.setText(title);
        invalidate();
    }

}
